﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
/// <summary>
/// 数据最大值接口
/// </summary>
public interface Imax {
    float GetMax (bool expand = true);
    float GetMin ();
}
/// <summary>
/// 数据值提取接口
/// </summary>
public interface Ivalues {
    Dictionary<string, List<float>> NameValues ();
}
public interface INames {
    List<string> GetNames ();
}

public class MultiLineData : Imax {
    public List<string> xAixsName = new List<string> ();
    public List<LineChartData> datas = new List<LineChartData> ();

    public float GetMax (bool expand = true) {
        float max = 0;
        foreach (var i in datas) {
            foreach (var value in i.lineValue)
                if (max < value.Value) max = value.Value;
        }
        if (expand) return max * 1.1f;
        return max;
    }

    public float GetMin () {
        float min = -1;
        foreach (var i in datas) {
            foreach (var value in i.lineValue)
                if (min == -1 || min > value.Value) min = value.Value;
        }
        return min;

    }
}

public class LineChartData {
    public bool IsDirty = false;
    public Dictionary<string, float> lineValue = new Dictionary<string, float> ();
}

/// <summary>
/// 对应单一名称多数值
/// </summary>
public class NameValueData {
    public bool isDirty = true;
    public string name;
    public List<float> value = new List<float> ();
}
public class NavaValueDataList {
    public List<NameValueData> datas = new List<NameValueData> ();
}

/// <summary>
/// 单名单数据 例子: 一号线：50
/// </summary>
public class SingleData {
    public string name;
    public float value;
    public SingleData () {

    }
    public SingleData (string name, float value) {
        this.name = name;
        this.value = value;
    }
    public static SingleData GetRandomData (string name) {
        return new SingleData () { name = name, value = Random.Range (50, 100) };
    }
    public static SingleData GetRandomData (int min, int max, string name = null) {
        return new SingleData () { name = name, value = Random.Range (Mathf.Max (min, 1), max) };
    }
}

//道路优良率专用
public class RoadGood : MultiDataGroup {
    public float distance = 0;
}

/// <summary>
/// 复合数据组
/// </summary>
public class MultiDataGroup : INames, Imax {
    public List<DataGroup> groups = new List<DataGroup> ();

    public float GetMax (bool expand = true) {
        float max = 0;
        foreach (var i in groups) {
            max = i.GetMax (expand) > max ? i.GetMax (expand) : max;
        }
        return max;
    }

    public float GetMin () {
        return 0;
    }

    public List<string> GetNames () {
        int count = 0;
        DataGroup maxData = null;
        foreach (var i in groups) {
            if (i.datas.Count > count) {
                count = i.datas.Count;
                maxData = i;
            }
        }
        List<string> names = new List<string> ();
        if (maxData == null) return null;
        foreach (var i in maxData.datas) {
            names.Add (i == null? "": i.name);
        }
        return names;

    }
}

public class StringMutiData : MultiDataGroup {
    public string carName;
}

public class carBonPlateGroup : MultiDataGroup {
    public new float GetMax (bool expand = false) {
        float max = 26.5f;
        foreach (var i in groups) {
            max = i.GetMax (expand) > max ? i.GetMax (expand) : max;
        }
        return max;
    }
}

/// <summary>
/// 一组数据 例子 
/// 总里程:{
/// 一号线:50
/// 二号线:30 }
/// </summary>
public class DataGroup : Imax, Ivalues {
    public string name;

    public List<SingleData> datas = new List<SingleData> ();

    public DataGroup () {

    }

    public DataGroup (string name, List<SingleData> datas) {
        this.datas = datas;
        this.name = name;
    }

    public float GetMax (bool expand = true) {
        float max = 0;
        foreach (var i in datas) {
            if (i.value > max) max = i.value;
        }
        if (expand) return max * 1.05f;
        return max;
    }

    /// <summary>
    /// 取得最小值
    /// </summary>
    /// <returns></returns>
    public float GetMin () {
        float max = -1;
        foreach (var i in datas) {
            if (max == -1 || i.value < max) max = i.value;
        }
        return max;
    }

    public List<string> GetName () {
        var values = from value in datas select value.name;
        return values.ToList ();
    }

    public List<List<float>> GetValues () {
        List<List<float>> vs = new List<List<float>> ();
        var values = from value in datas select value.value;
        vs.Add (values.ToList ());
        return vs;
    }
    public Dictionary<string, List<float>> NameValues () {
        var dic = new Dictionary<string, List<float>> ();
        foreach (var i in datas) { dic.Add (i.name, new List<float> () { i.value }); }
        return dic;
    }
}

public class MaxPassengerFlow : DataGroup {
    //历史最大日期
    public string maxDate;
    //最大客流量 
    public float maxFlow;

}

public class PumpData {
    public string Name;
    public float Pump;
    public float Stop;
    public float Error;
    public float Running;
    public PumpData () { }

    public PumpData (string name, float pump, float stop, float error, float running) {
        Name = name;
        Pump = pump;
        Stop = stop;
        Error = error;
        Running = running;
    }
}

public class PumpDataGroup {
    public List<PumpData> datas = new List<PumpData> ();
}

public class WarningItem {
    public string time;
    public string carNum;
    public string carRoomNum;
    public string turn;
    public string testPoin;
    public string warningLevel;
    public string warningMsg;
}
public class WarningDataList {
    public List<WarningItem> datas = new List<WarningItem> ();
}
/// <summary>
/// 告警信息专用
/// </summary>
public class WarningMsg {
    public string date;
    public string warningLevel;
    public string msg;
}